package com.nine.gxh.consumer;

import com.rabbitmq.client.Channel;
import com.ruoyi.common.constant.MyRabbitDelayConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Date;

/**
 * @author: duonine
 * @date: 2023/7/7
 */
@Slf4j
@Component
public class GxhDelayLetterConsumer {

    /**
     * 设置10s的延时队列消费者
     * @param message
     * @param channel
     * @throws IOException
     */
    @RabbitListener(queues = MyRabbitDelayConstants.DEAD_LETTER_QUEUE_NAME_A)
    public void receiveA(Message message, Channel channel) throws IOException {
        String msg = new String(message.getBody());
        log.info("当前时间：{},死信队列A收到消息：{}", new Date().toString(), msg);
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }

    /**
     * 设置30s的延时队列消费者
     * @param message
     * @param channel
     * @throws IOException
     */
    @RabbitListener(queues = MyRabbitDelayConstants.DEAD_LETTER_QUEUE_NAME_B)
    public void receiveB(Message message, Channel channel) throws IOException {
        String msg = new String(message.getBody());
        log.info("当前时间：{},死信队列B收到消息：{}", new Date().toString(), msg);
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }

}
